﻿namespace TestNewGuiFramework
{
    using Pps.Gui.Controls;

    internal class HeatingWindow : BaseWindow
    {
        private static float gradientValue = 0.3F;

        private Label forwardTemperature;
        private Label backwardTemperature;
        private Label flow;
        private Label state;
        private Label gradient;
        private Label heatpower;

        private Button gradientUp;
        private Button gradientDown;

        public HeatingWindow()
        {
            this.InitializeControls();
        }

        protected override void InitializeControls()
        {
            base.InitializeControls();

            this.state = new Label("Status: Manuell", 280, 50);

            this.forwardTemperature = new Label("Vorlauftemperatur: 34.5 °C", 280, 120);

            this.backwardTemperature = new Label("Rücklauftemperatur: 29.5 °C", 280, 190);

            this.flow = new Label("Durchfluss: 1745 L/h", 280, 260);

            this.gradient = new Label("Steilheit: " + (gradientValue * 100).ToString("F0") + " %", 280, 330);
            this.gradient.AutoSize = false;
            this.gradient.Size = new Pps.Gui.Base.Size(310, 70);

            this.gradientUp = new Button("+", 590, 330, 40, 40);
            this.gradientUp.Clicked += GradientUp;

            this.gradientDown = new Button("-", 650, 330, 40, 40);
            this.gradientDown.Clicked += GradientDown;

            this.heatpower = new Label("Heizleistung: 10.7 kW", 280, 400);

            this.heating.Selected = true;
            this.heating.Enabled = false;

            this.AddControlsToWindow();
        }

        private void GradientDown()
        {
            gradientValue -= 0.01F;
            this.gradient.Text = "Steilheit: " + (gradientValue * 100).ToString("F0") + " %";
        }

        private void GradientUp()
        {
            gradientValue += 0.01F;
            this.gradient.Text = "Steilheit: " + (gradientValue * 100).ToString("F0") + " %";
        }

        protected override void AddControlsToWindow()
        {
            base.AddControlsToWindow();

            this.AddChildControl(this.state);
            this.AddChildControl(this.forwardTemperature);
            this.AddChildControl(this.backwardTemperature);
            this.AddChildControl(this.flow);
            this.AddChildControl(this.gradient);
            this.AddChildControl(this.heatpower);
            this.AddChildControl(this.gradientUp);
            this.AddChildControl(this.gradientDown);
        }

        protected override void Update()
        {
            System.Random test = new System.Random();

            this.forwardTemperature.Text = "Vorlauftemperatur: " + test.Next(100).ToString("F1") + " °C";
            this.backwardTemperature.Text = "Rücklauftemperatur: " + test.Next(100).ToString("F1") + " °C";
            this.flow.Text = "Durchfluss: " + test.Next(2000).ToString("F2") + " L/h";
        }
    }
}